6 public static void main(String
[] args
) throws IOException
{
7 BufferedReader reader
=
8 new BufferedReader(new InputStreamReader(System
.in
));
9 String line
= reader
.readLine();
10 StringTokenizer tokenizer
= new StringTokenizer(line
);
11 int N
= Integer
.valueOf(tokenizer
.nextToken());
14 a
= reader
.readLine();
15 b
= reader
.readLine();
17 int A
= a
.length(), B
= b
.length();
19 System
.out
.println("0");
21 BigInteger dp
[][] = new BigInteger
[2][A
];
23 dp[i][j] = cantidad de maneras diferentes
24 en que puedo distribuir las primeras i
25 letras de la subsecuencia (b) terminando
26 en la letra j de la secuencia original (a)
29 if (a
.charAt(0) == b
.charAt(0)){
30 dp
[0][0] = BigInteger
.ONE
;
32 dp
[0][0] = BigInteger
.ZERO
;
34 for (int j
=1; j
<A
; ++j
){
35 dp
[0][j
] = dp
[0][j
-1];
36 if (a
.charAt(j
) == b
.charAt(0)){
37 dp
[0][j
] = dp
[0][j
].add(BigInteger
.ONE
);
41 for (int i
=1; i
<B
; ++i
){
42 dp
[i
%2][0] = BigInteger
.ZERO
;
43 for (int j
=1; j
<A
; ++j
){
44 dp
[i
%2][j
] = dp
[i
%2][j
-1];
45 if (a
.charAt(j
) == b
.charAt(i
)){
46 dp
[i
%2][j
] = dp
[i
%2][j
].add(dp
[(i
+1)%2][j
-1]);
50 System
.out
.println(dp
[(B
-1)%2][A
-1].toString());